package Chan

import "time"

type Event struct {
	ch chan interface{}
}

func NewEvent() *Event {
	ptr := &Event{}
	ptr.ch = make(chan interface{}, 1)
	return ptr
}

func (e *Event) Close() {
	close(e.ch)
	e.ch = nil
}

func (e *Event) Notify(data interface{}) {
	e.ch <- data
}

func (e *Event) Wait(timeout int64) interface{} {
	select {
	case message := <-e.ch:
		return message
	case <-time.After(time.Duration(timeout) * time.Millisecond):
		return nil
	}
}
